// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Code generated by sidekick. DO NOT EDIT.

#[allow(unused_imports)]
use super::*;

#[doc(hidden)]
impl<'de> serde::de::Deserialize<'de> for super::GmailAddOnManifest {
    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        #[allow(non_camel_case_types)]
        #[doc(hidden)]
        #[derive(PartialEq, Eq, Hash)]
        enum __FieldTag {
            __homepage_trigger,
            __contextual_triggers,
            __universal_actions,
            __compose_trigger,
            __authorization_check_function,
            Unknown(std::string::String),
        }
        impl<'de> serde::de::Deserialize<'de> for __FieldTag {
            fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
            where
                D: serde::Deserializer<'de>,
            {
                struct Visitor;
                impl<'de> serde::de::Visitor<'de> for Visitor {
                    type Value = __FieldTag;
                    fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
                        formatter.write_str("a field name for GmailAddOnManifest")
                    }
                    fn visit_str<E>(self, value: &str) -> std::result::Result<Self::Value, E>
                    where
                        E: serde::de::Error,
                    {
                        use std::result::Result::Ok;
                        use std::string::ToString;
                        match value {
                            "homepageTrigger" => Ok(__FieldTag::__homepage_trigger),
                            "homepage_trigger" => Ok(__FieldTag::__homepage_trigger),
                            "contextualTriggers" => Ok(__FieldTag::__contextual_triggers),
                            "contextual_triggers" => Ok(__FieldTag::__contextual_triggers),
                            "universalActions" => Ok(__FieldTag::__universal_actions),
                            "universal_actions" => Ok(__FieldTag::__universal_actions),
                            "composeTrigger" => Ok(__FieldTag::__compose_trigger),
                            "compose_trigger" => Ok(__FieldTag::__compose_trigger),
                            "authorizationCheckFunction" => {
                                Ok(__FieldTag::__authorization_check_function)
                            }
                            "authorization_check_function" => {
                                Ok(__FieldTag::__authorization_check_function)
                            }
                            _ => Ok(__FieldTag::Unknown(value.to_string())),
                        }
                    }
                }
                deserializer.deserialize_identifier(Visitor)
            }
        }
        struct Visitor;
        impl<'de> serde::de::Visitor<'de> for Visitor {
            type Value = super::GmailAddOnManifest;
            fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
                formatter.write_str("struct GmailAddOnManifest")
            }
            fn visit_map<A>(self, mut map: A) -> std::result::Result<Self::Value, A::Error>
            where
                A: serde::de::MapAccess<'de>,
            {
                #[allow(unused_imports)]
                use serde::de::Error;
                use std::option::Option::Some;
                let mut fields = std::collections::HashSet::new();
                let mut result = Self::Value::new();
                while let Some(tag) = map.next_key::<__FieldTag>()? {
                    #[allow(clippy::match_single_binding)]
                    match tag {
                        __FieldTag::__homepage_trigger => {
                            if !fields.insert(__FieldTag::__homepage_trigger) {
                                return std::result::Result::Err(A::Error::duplicate_field(
                                    "multiple values for homepage_trigger",
                                ));
                            }
                            result.homepage_trigger = map.next_value::<std::option::Option<
                                apps_script_type::model::HomepageExtensionPoint,
                            >>()?;
                        }
                        __FieldTag::__contextual_triggers => {
                            if !fields.insert(__FieldTag::__contextual_triggers) {
                                return std::result::Result::Err(A::Error::duplicate_field(
                                    "multiple values for contextual_triggers",
                                ));
                            }
                            result.contextual_triggers =
                                map.next_value::<std::option::Option<
                                    std::vec::Vec<crate::model::ContextualTrigger>,
                                >>()?
                                .unwrap_or_default();
                        }
                        __FieldTag::__universal_actions => {
                            if !fields.insert(__FieldTag::__universal_actions) {
                                return std::result::Result::Err(A::Error::duplicate_field(
                                    "multiple values for universal_actions",
                                ));
                            }
                            result.universal_actions =
                                map.next_value::<std::option::Option<
                                    std::vec::Vec<crate::model::UniversalAction>,
                                >>()?
                                .unwrap_or_default();
                        }
                        __FieldTag::__compose_trigger => {
                            if !fields.insert(__FieldTag::__compose_trigger) {
                                return std::result::Result::Err(A::Error::duplicate_field(
                                    "multiple values for compose_trigger",
                                ));
                            }
                            result.compose_trigger = map
                                .next_value::<std::option::Option<crate::model::ComposeTrigger>>(
                                )?;
                        }
                        __FieldTag::__authorization_check_function => {
                            if !fields.insert(__FieldTag::__authorization_check_function) {
                                return std::result::Result::Err(A::Error::duplicate_field(
                                    "multiple values for authorization_check_function",
                                ));
                            }
                            result.authorization_check_function = map
                                .next_value::<std::option::Option<std::string::String>>()?
                                .unwrap_or_default();
                        }
                        __FieldTag::Unknown(key) => {
                            let value = map.next_value::<serde_json::Value>()?;
                            result._unknown_fields.insert(key, value);
                        }
                    }
                }
                std::result::Result::Ok(result)
            }
        }
        deserializer.deserialize_any(Visitor)
    }
}

#[doc(hidden)]
impl<'de> serde::de::Deserialize<'de> for super::UniversalAction {
    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        #[allow(non_camel_case_types)]
        #[doc(hidden)]
        #[derive(PartialEq, Eq, Hash)]
        enum __FieldTag {
            __text,
            __open_link,
            __run_function,
            Unknown(std::string::String),
        }
        impl<'de> serde::de::Deserialize<'de> for __FieldTag {
            fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
            where
                D: serde::Deserializer<'de>,
            {
                struct Visitor;
                impl<'de> serde::de::Visitor<'de> for Visitor {
                    type Value = __FieldTag;
                    fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
                        formatter.write_str("a field name for UniversalAction")
                    }
                    fn visit_str<E>(self, value: &str) -> std::result::Result<Self::Value, E>
                    where
                        E: serde::de::Error,
                    {
                        use std::result::Result::Ok;
                        use std::string::ToString;
                        match value {
                            "text" => Ok(__FieldTag::__text),
                            "openLink" => Ok(__FieldTag::__open_link),
                            "open_link" => Ok(__FieldTag::__open_link),
                            "runFunction" => Ok(__FieldTag::__run_function),
                            "run_function" => Ok(__FieldTag::__run_function),
                            _ => Ok(__FieldTag::Unknown(value.to_string())),
                        }
                    }
                }
                deserializer.deserialize_identifier(Visitor)
            }
        }
        struct Visitor;
        impl<'de> serde::de::Visitor<'de> for Visitor {
            type Value = super::UniversalAction;
            fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
                formatter.write_str("struct UniversalAction")
            }
            fn visit_map<A>(self, mut map: A) -> std::result::Result<Self::Value, A::Error>
            where
                A: serde::de::MapAccess<'de>,
            {
                #[allow(unused_imports)]
                use serde::de::Error;
                use std::option::Option::Some;
                let mut fields = std::collections::HashSet::new();
                let mut result = Self::Value::new();
                while let Some(tag) = map.next_key::<__FieldTag>()? {
                    #[allow(clippy::match_single_binding)]
                    match tag {
                        __FieldTag::__text => {
                            if !fields.insert(__FieldTag::__text) {
                                return std::result::Result::Err(A::Error::duplicate_field(
                                    "multiple values for text",
                                ));
                            }
                            result.text = map
                                .next_value::<std::option::Option<std::string::String>>()?
                                .unwrap_or_default();
                        }
                        __FieldTag::__open_link => {
                            if !fields.insert(__FieldTag::__open_link) {
                                return std::result::Result::Err(A::Error::duplicate_field(
                                    "multiple values for open_link",
                                ));
                            }
                            if result.action_type.is_some() {
                                return std::result::Result::Err(A::Error::duplicate_field(
                                    "multiple values for `action_type`, a oneof with full ID .google.apps.script.type.gmail.UniversalAction.open_link, latest field was openLink",
                                ));
                            }
                            result.action_type = std::option::Option::Some(
                                crate::model::universal_action::ActionType::OpenLink(
                                    map.next_value::<std::option::Option<std::string::String>>()?
                                        .unwrap_or_default(),
                                ),
                            );
                        }
                        __FieldTag::__run_function => {
                            if !fields.insert(__FieldTag::__run_function) {
                                return std::result::Result::Err(A::Error::duplicate_field(
                                    "multiple values for run_function",
                                ));
                            }
                            if result.action_type.is_some() {
                                return std::result::Result::Err(A::Error::duplicate_field(
                                    "multiple values for `action_type`, a oneof with full ID .google.apps.script.type.gmail.UniversalAction.run_function, latest field was runFunction",
                                ));
                            }
                            result.action_type = std::option::Option::Some(
                                crate::model::universal_action::ActionType::RunFunction(
                                    map.next_value::<std::option::Option<std::string::String>>()?
                                        .unwrap_or_default(),
                                ),
                            );
                        }
                        __FieldTag::Unknown(key) => {
                            let value = map.next_value::<serde_json::Value>()?;
                            result._unknown_fields.insert(key, value);
                        }
                    }
                }
                std::result::Result::Ok(result)
            }
        }
        deserializer.deserialize_any(Visitor)
    }
}

#[doc(hidden)]
impl<'de> serde::de::Deserialize<'de> for super::ComposeTrigger {
    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        #[allow(non_camel_case_types)]
        #[doc(hidden)]
        #[derive(PartialEq, Eq, Hash)]
        enum __FieldTag {
            __actions,
            __draft_access,
            Unknown(std::string::String),
        }
        impl<'de> serde::de::Deserialize<'de> for __FieldTag {
            fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
            where
                D: serde::Deserializer<'de>,
            {
                struct Visitor;
                impl<'de> serde::de::Visitor<'de> for Visitor {
                    type Value = __FieldTag;
                    fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
                        formatter.write_str("a field name for ComposeTrigger")
                    }
                    fn visit_str<E>(self, value: &str) -> std::result::Result<Self::Value, E>
                    where
                        E: serde::de::Error,
                    {
                        use std::result::Result::Ok;
                        use std::string::ToString;
                        match value {
                            "actions" => Ok(__FieldTag::__actions),
                            "draftAccess" => Ok(__FieldTag::__draft_access),
                            "draft_access" => Ok(__FieldTag::__draft_access),
                            _ => Ok(__FieldTag::Unknown(value.to_string())),
                        }
                    }
                }
                deserializer.deserialize_identifier(Visitor)
            }
        }
        struct Visitor;
        impl<'de> serde::de::Visitor<'de> for Visitor {
            type Value = super::ComposeTrigger;
            fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
                formatter.write_str("struct ComposeTrigger")
            }
            fn visit_map<A>(self, mut map: A) -> std::result::Result<Self::Value, A::Error>
            where
                A: serde::de::MapAccess<'de>,
            {
                #[allow(unused_imports)]
                use serde::de::Error;
                use std::option::Option::Some;
                let mut fields = std::collections::HashSet::new();
                let mut result = Self::Value::new();
                while let Some(tag) = map.next_key::<__FieldTag>()? {
                    #[allow(clippy::match_single_binding)]
                    match tag {
                        __FieldTag::__actions => {
                            if !fields.insert(__FieldTag::__actions) {
                                return std::result::Result::Err(A::Error::duplicate_field(
                                    "multiple values for actions",
                                ));
                            }
                            result.actions = map
                                .next_value::<std::option::Option<
                                    std::vec::Vec<apps_script_type::model::MenuItemExtensionPoint>,
                                >>()?
                                .unwrap_or_default();
                        }
                        __FieldTag::__draft_access => {
                            if !fields.insert(__FieldTag::__draft_access) {
                                return std::result::Result::Err(A::Error::duplicate_field(
                                    "multiple values for draft_access",
                                ));
                            }
                            result.draft_access = map.next_value::<std::option::Option<crate::model::compose_trigger::DraftAccess>>()?.unwrap_or_default();
                        }
                        __FieldTag::Unknown(key) => {
                            let value = map.next_value::<serde_json::Value>()?;
                            result._unknown_fields.insert(key, value);
                        }
                    }
                }
                std::result::Result::Ok(result)
            }
        }
        deserializer.deserialize_any(Visitor)
    }
}

#[doc(hidden)]
impl<'de> serde::de::Deserialize<'de> for super::ContextualTrigger {
    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        #[allow(non_camel_case_types)]
        #[doc(hidden)]
        #[derive(PartialEq, Eq, Hash)]
        enum __FieldTag {
            __unconditional,
            __on_trigger_function,
            Unknown(std::string::String),
        }
        impl<'de> serde::de::Deserialize<'de> for __FieldTag {
            fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
            where
                D: serde::Deserializer<'de>,
            {
                struct Visitor;
                impl<'de> serde::de::Visitor<'de> for Visitor {
                    type Value = __FieldTag;
                    fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
                        formatter.write_str("a field name for ContextualTrigger")
                    }
                    fn visit_str<E>(self, value: &str) -> std::result::Result<Self::Value, E>
                    where
                        E: serde::de::Error,
                    {
                        use std::result::Result::Ok;
                        use std::string::ToString;
                        match value {
                            "unconditional" => Ok(__FieldTag::__unconditional),
                            "onTriggerFunction" => Ok(__FieldTag::__on_trigger_function),
                            "on_trigger_function" => Ok(__FieldTag::__on_trigger_function),
                            _ => Ok(__FieldTag::Unknown(value.to_string())),
                        }
                    }
                }
                deserializer.deserialize_identifier(Visitor)
            }
        }
        struct Visitor;
        impl<'de> serde::de::Visitor<'de> for Visitor {
            type Value = super::ContextualTrigger;
            fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
                formatter.write_str("struct ContextualTrigger")
            }
            fn visit_map<A>(self, mut map: A) -> std::result::Result<Self::Value, A::Error>
            where
                A: serde::de::MapAccess<'de>,
            {
                #[allow(unused_imports)]
                use serde::de::Error;
                use std::option::Option::Some;
                let mut fields = std::collections::HashSet::new();
                let mut result = Self::Value::new();
                while let Some(tag) = map.next_key::<__FieldTag>()? {
                    #[allow(clippy::match_single_binding)]
                    match tag {
                        __FieldTag::__unconditional => {
                            if !fields.insert(__FieldTag::__unconditional) {
                                return std::result::Result::Err(A::Error::duplicate_field(
                                    "multiple values for unconditional",
                                ));
                            }
                            if result.trigger.is_some() {
                                return std::result::Result::Err(A::Error::duplicate_field(
                                    "multiple values for `trigger`, a oneof with full ID .google.apps.script.type.gmail.ContextualTrigger.unconditional, latest field was unconditional",
                                ));
                            }
                            result.trigger = std::option::Option::Some(
                                crate::model::contextual_trigger::Trigger::Unconditional(
                                    map.next_value::<std::option::Option<
                                        std::boxed::Box<crate::model::UnconditionalTrigger>,
                                    >>()?
                                    .unwrap_or_default(),
                                ),
                            );
                        }
                        __FieldTag::__on_trigger_function => {
                            if !fields.insert(__FieldTag::__on_trigger_function) {
                                return std::result::Result::Err(A::Error::duplicate_field(
                                    "multiple values for on_trigger_function",
                                ));
                            }
                            result.on_trigger_function = map
                                .next_value::<std::option::Option<std::string::String>>()?
                                .unwrap_or_default();
                        }
                        __FieldTag::Unknown(key) => {
                            let value = map.next_value::<serde_json::Value>()?;
                            result._unknown_fields.insert(key, value);
                        }
                    }
                }
                std::result::Result::Ok(result)
            }
        }
        deserializer.deserialize_any(Visitor)
    }
}

#[doc(hidden)]
impl<'de> serde::de::Deserialize<'de> for super::UnconditionalTrigger {
    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        #[allow(non_camel_case_types)]
        #[doc(hidden)]
        #[derive(PartialEq, Eq, Hash)]
        enum __FieldTag {
            Unknown(std::string::String),
        }
        impl<'de> serde::de::Deserialize<'de> for __FieldTag {
            fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
            where
                D: serde::Deserializer<'de>,
            {
                struct Visitor;
                impl<'de> serde::de::Visitor<'de> for Visitor {
                    type Value = __FieldTag;
                    fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
                        formatter.write_str("a field name for UnconditionalTrigger")
                    }
                    fn visit_str<E>(self, value: &str) -> std::result::Result<Self::Value, E>
                    where
                        E: serde::de::Error,
                    {
                        use std::result::Result::Ok;
                        use std::string::ToString;
                        Ok(__FieldTag::Unknown(value.to_string()))
                    }
                }
                deserializer.deserialize_identifier(Visitor)
            }
        }
        struct Visitor;
        impl<'de> serde::de::Visitor<'de> for Visitor {
            type Value = super::UnconditionalTrigger;
            fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
                formatter.write_str("struct UnconditionalTrigger")
            }
            fn visit_map<A>(self, mut map: A) -> std::result::Result<Self::Value, A::Error>
            where
                A: serde::de::MapAccess<'de>,
            {
                #[allow(unused_imports)]
                use serde::de::Error;
                use std::option::Option::Some;
                let mut result = Self::Value::new();
                while let Some(tag) = map.next_key::<__FieldTag>()? {
                    #[allow(clippy::match_single_binding)]
                    match tag {
                        __FieldTag::Unknown(key) => {
                            let value = map.next_value::<serde_json::Value>()?;
                            result._unknown_fields.insert(key, value);
                        }
                    }
                }
                std::result::Result::Ok(result)
            }
        }
        deserializer.deserialize_any(Visitor)
    }
}
